package com.sugar.web.struts.oa.hr;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.sugar.common.query.PageView;
import com.sugar.common.tools.ParseArrayUtil;
import com.sugar.domain.oa.hr.Organization;
import com.sugar.service.oa.hr.IOrganizationService;
import com.sugar.web.struts.BaseActionSupport;

@Controller
@Scope("prototype")
public class OrganizationAction extends BaseActionSupport {

	private static final long serialVersionUID = 1L;

	private Organization org;

	private String delIds;

	public String getDelIds() {
		return delIds;
	}

	public void setDelIds(String delIds) {
		this.delIds = delIds;
	}

	@Resource
	private PageView<Organization> pageView;

	public PageView<Organization> getPageView() {
		return pageView;
	}
	private String type ;

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public void setPageView(PageView<Organization> pageView) {
		this.pageView = pageView;
	}

	public Organization getOrg() {
		return org;
	}

	public void setOrg(Organization org) {
		this.org = org;
	}

	@Resource
	private IOrganizationService orgs;

	public String getOrgAction() {
		getRequest().setAttribute("org",this.orgs.loadOrgByIdService(org.getOrgCode()));
		if("update".equals(type)) {
			return "update" ;
		} else {
			return "get" ;
		}
	}

	public String findOrgAction() {

		getRequest().setAttribute("org", this.orgs.findOrgService(null));

		return SUCCESS;
	}

	public String updateOrgAction() {

		
		this.orgs.updateOrgService(org);

		return "updateSuccess";
	}

	public String getScrollOrgAction() {
		this.pageView.setPageModel(this.orgs.getScorllOrgService(null,
				this.pageView.getFirstResult(), this.pageView.getMaxResult()));

		getRequest().setAttribute("pageView", pageView);

		return "getScrollSuccess";

	}

	public String deleteSelectOrgAction() {

		this.orgs.deleteSelectOrgService(ParseArrayUtil.parseArray(delIds));

		return "deleteSelectSuccess";
	}

	public String addOrgAction() {

		this.orgs.saveOrgService(org);

		return "saveSuccess";
	}

}
